package chapter06

/**
 *
 * @author cdhuangchao3
 * @date 2023/6/9 7:31 PM
 */
object Test13_Trait {
  def main(args: Array[String]): Unit = {
    val student = new Student13
    student.sayHello()
    student.dating()
    student.study()
    student.play()
  }
}

// 定义一个父类
class Person13 {
  val name: String = "person"
  var age: Int = 18

  def sayHello(): Unit = {
    println(s"hello from : ${name}")
  }

  def increase(): Unit = {
    println("person increased")
  }
}

// 定义一个特质
trait Young {
  // 声明抽象和非抽象属性
  var age: Int
  val name: String = "young"

  // 声明抽象、非抽象方法
  def play(): Unit = {
    println(s"young people ${name} is playing")
  }

  def dating(): Unit
}

class Student13 extends Person13 with Young {
  override val  name: String = "student"

  override def dating(): Unit = println(s"student ${name} is dating")

  def study() = println(s"studeng ${name} is studying")

  override def sayHello(): Unit = {
    super.sayHello()
    println(s"hello from student : ${name}")
  }
}
